#ifndef _ATOMIC_0701_ZXZL_H_
#define _ATOMIC_0701_ZXZL_H_

/*------------------------ Include Begin --------------------------*/

// C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <time.h>
#include <ctype.h>

// C++
#include <iostream>
#include <fstream>
#include <chrono>
#include <string>
#include <random>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <sstream>

/*------------------------  Include End  -------------------------*/

/*------------------------  Service Info Begin  --------------------------*/
/**
 *
 * @name:    atomic_0701_zlsc
 * @chinese_name: 执行器指令
 * @description: information about atomic_0701_zlsc
 * @version: V1.0.0
 * @build_time: 2024-09-21T09-21-21
 * @license: MIT
 * @service_path: /atomic_0701_zlsc
 *
 * @resource_requirement:
 *         + cpu_architecture: x86_64
 *         + memory: 4GB
 *         + hard_disk: 50GB
 *
 *@developer:
 *      +name: Spiderman
 *      +email: Spidermsan@atomic_service_fwgz.com
 *@maintainer:
 *      +name:IronMan
 *      +email:ironman@PNUI.com
 *@operating_system:
 *      +name:Linux
 *      +v1:5.13.0-117-generic
 *      +v2:5.14.0-117-generic
 *      +name:SylixOS
 *      +v1:1.0.0
 *      +v2:1.0.2
 *
 *
 *
 */
/*------------------------  Service Info End  --------------------------*/

/*------------------------  Return Type Begin  --------------------------*/

#define ATOMIC_SERVICE_SUCCESS 0
#define ATOMIC_SERVICE_FAIL -1
#define ATOMIC_SERVICE_TIMEOUT -2
#define ATOMIC_SERVICE_ERROR -3
#define ATOMIC_SERVICE_NOT_SUPPORT -4
#define ATOMIC_SERVICE_NOT_READY -5
#define ATOMIC_SERVICE_NOT_INIT -6
#define ATOMIC_SERVICE_NOT_START -7
#define ATOMIC_SERVICE_NOT_STOP -8
#define ATOMIC_SERVICE_NOT_RELEASE -9
#define ATOMIC_SERVICE_NOT_DESTROY -10
#define ATOMIC_SERVICE_NOT_CREATE -11
#define ATOMIC_SERVICE_NOT_OPEN -12
#define ATOMIC_SERVICE_NOT_CLOSE -13
#define ATOMIC_SERVICE_NOT_READ -14
#define ATOMIC_SERVICE_NOT_WRITE -15
#define ATOMIC_SERVICE_NOT_SEEK -16
#define ATOMIC_SERVICE_NOT_TELL -17
#define ATOMIC_SERVICE_NOT_SIZE -18
#define ATOMIC_SERVICE_NOT_SEEK_END -19
#define ATOMIC_SERVICE_NOT_SEEK_SET -20
#define ATOMIC_SERVICE_NOT_SEEK_CUR -21
#define ATOMIC_SERVICE_NOT_SEEK_ABS -22

/*------------------------  Return Type End  --------------------------*/

// 安全范围定义
#define PI 3.14159265358979323846
#define MIN_ACTUATOR_VALUE -1.0
#define MAX_ACTUATOR_VALUE 1.0
#define MIN_THROTTLE_VALUE 0.0
#define MAX_THROTTLE_VALUE 1.0

/*------------------------  Message Info Begin  --------------------------*/

// 执行器指令输入参数 (基本数据类型)
typedef struct {
    double pitch_command;        // 俯仰控制指令
    double yaw_command;         // 偏航控制指令
    double roll_command;        // 滚转控制指令
    double throttle_command;    // 油门控制指令
    double missile_velocity;    // 当前导弹速度(m/s)
    double missile_altitude;    // 当前导弹高度(m)
    double missile_angle;       // 当前导弹角度(度)
    double actuator_health[4];  // 执行器健康状态(0-1)
    double max_actuator_rate;  // 执行器最大变化率
    double timestamp;          // 时间戳(s)
} ActuatorCommandInput;

// 执行器指令输出参数 (基本数据类型)
typedef struct {
    double fin1_position;      // 舵面1位置(-1到1)
    double fin2_position;      // 舵面2位置(-1到1)
    double fin3_position;      // 舵面3位置(-1到1)
    double fin4_position;      // 舵面4位置(-1到1)
    double throttle_position;  // 油门位置(0到1)
    double fin1_rate;          // 舵面1变化率
    double fin2_rate;          // 舵面2变化率
    double fin3_rate;          // 舵面3变化率
    double fin4_rate;          // 舵面4变化率
    double throttle_rate;      // 油门变化率
    double actuator_effort;    // 执行器努力程度(0-1)
    double health_status;      // 综合健康状态(0-1)
    double saturation_level;   // 饱和程度(0-1)
    double cross_coupling;     // 交叉耦合效应
    double hysteresis_compensation; // 迟滞补偿
    double backlash_compensation;  // 齿隙补偿
    double predictive_positioning; // 预测定位
} ActuatorCommandOutput;

/*------------------------  Message Info End  --------------------------*/

// 执行器模型
typedef struct {
    double position[4];       // 四个舵面当前位置
    double throttle_position; // 油门当前位置
    double rate_limit;        // 速率限制
    double hysteresis[4];     // 舵面迟滞
    double backlash[4];       // 舵面齿隙
    double last_command[4];   // 上次指令
    double last_throttle;     // 上次油门指令
} ActuatorModel;

/*------------------------  Interface Declaration Begin  --------------------------*/


// 执行器指令函数
int generateActuatorCommands(ActuatorCommandInput *input, ActuatorCommandOutput *output);

/*------------------------  Interface Declaration End  --------------------------*/

// 初始化执行器模型
void initActuatorModel(ActuatorModel *model, double rate_limit);
// 更新执行器模型
void updateActuatorModel(ActuatorModel *model, double commands[4], double throttle,
                         double health[4], double dt);

#endif // _ATOMIC_0701_ZXZL_H_
